<!DOCTYPE html>

<html lang="en-us"><head>
  <meta charset="utf-8">
  <title>欢迎来到中国非物质文化遗产论坛</title>
  <script src="js/vue.js"></script>
  <script src="./js/axios.js"></script>

  <!-- mobile responsive meta -->
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="This is meta description">
  <meta name="generator" content="Hugo 0.74.3" />

  <!-- plugins -->
  
  <link rel="stylesheet" href="plugins/bootstrap/bootstrap.css">
  <link rel="stylesheet" href="plugins/themify-icons/themify-icons.css">
  <link rel="stylesheet" href="plugins/slick/slick.css">

  <!-- Main Stylesheet -->
  <link rel="stylesheet" href="css/style.css" media="screen">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">

  <!--Favicon-->
  <link rel="shortcut icon" href="images/favicon.png" type="image/x-icon">
  <link rel="icon" href="images/favicon.png" type="image/x-icon">
  

  <meta property="og:title" content="Reader | Hugo Personal Blog Template" />
  <meta property="og:description" content="This is meta description" />
  <meta property="og:type" content="website" />
  <meta property="og:url" content="" />
  <meta property="og:updated_time" content="2020-03-15T15:40:24+06:00" />
</head>
<body>

  <!-- navigation -->
 <!-- navigation -->
 <!-- navigation -->
 <header class="navigation">
  <div class="container" id="index">
    <nav class="navbar navbar-expand-lg navbar-white">
      <a class="navbar-brand order-1" href="index.html">
        <img class="img-fluid" width="50px" src="images/图标.png"
          alt="中国传统文化论坛">
      </a>
      <div class="collapse navbar-collapse text-center order-lg-2 order-3" id="navigation">
        <ul class="navbar-nav mx-auto">
          <li class="nav-item active">
            <a class="nav-link" href="index.html">首页</a>
          </li>
          <li class="nav-item @@about__active">
            <a class="nav-link" href="BBS_index.html">论坛</a>
          </li>
          <li class="nav-item @@services__active">
            <a class="nav-link" href="chat.html">消息</a>
          </li>
          <li class="nav-item @@services__active">
            <a class="nav-link" href="shop.html">商店</a>
          </li>
        </ul>
      </div>
      <div class="order-2 order-lg-3 d-flex align-items-center">
        <form @submit.prevent="performSearch"> <!-- 阻止表单提交 -->
          <input 
            id="search-query" 
            name="s" 
            type="search" 
            placeholder="输入文章ID"
            v-model="searchId" 
          >
          <button type="submit" class="btn btn-search">搜索</button> <!-- 搜索按钮 -->
        </form>
        <button class="navbar-toggler border-0 order-1" type="button" data-toggle="collapse" data-target="#navigation">
          <i class="ti-menu"></i>
        </button>
        <ul class="navbar-nav ml-auto" v-if="userid==null">
          <li class="nav-item @@login__active">
              <a class="nav-link" href="Login.html">登录</a>
          </li>
          <li class="nav-item @@register__active">
              <a class="nav-link" href="register.html">注册</a>
          </li>
      </ul>
      <ul class="navbar-nav ml-auto 1ogined" v-else>
          <li class="nav-item @@login__active">
            <span><a class="nav-link" href="person-post.html">{{userid}}</a></span>
          </li>
          <li class="nav-item @@register__active">
              <span v-on:click.prevent="logout"><a class="nav-link" href="BBS_index.html">注销</a></span>
          </li>
      </ul>
      </div>
    </nav>
  </div>
</header>
  <!--引导程序-->
  <script src="js/jquery-3.3.1.min.js"></script> 
  <script src="js/bootstrap.min.js"></script>
  <!--/MENU-JS-->
  <script>
      new Vue({
        el: "#index",
        data: {
          userid: localStorage["userid"],
          searchId: '' // 用于存储搜索的ID
        },
        methods: {
          logout: function() {
            localStorage.clear();
            this.userid = null;
          },
          performSearch: function() {
            if (!this.searchId || this.searchId.trim() === '') {
              alert("请输入文章id")
              return;
            }
            // 存储搜索ID到localStorage
            localStorage.setItem("num", this.searchId);
            // 跳转到post.html
            location.href = "post.html";
          }
        }
      })
  </script>
  <div id="chat">
    <!-- 悬浮聊天按钮 -->
    <button class="chat-button" @click="toggleChatBox">
      <i class="fas fa-comments"></i>
    </button>

    <!-- 左侧聊天框 -->
    <div v-show="showChatBox" class="chat-box">
      <div class="chat-header">聊天机器人</div>
      <div class="messages">
        <div v-for="msg in messages" :key="msg.id" class="message">
          <div v-if="msg.type === 'user'" class="user">{{ msg.text }}</div>
          <div v-if="msg.type === 'bot'" class="bot">{{ msg.text }}</div>
        </div>
      </div>
      <div class="input-container">
        <input v-model="userInput" type="text" placeholder="请输入问题...">
        <button @click="sendMessage">发送</button>
      </div>
    </div>
  </div>

<script>
  new Vue({
    el: '#chat',
    data: {
      showChatBox: false, // 确保初始值为 true 或者通过逻辑控制它显示
      userInput: '', // 用户输入的消息
      messages: [] // 消息列表
    },
    methods: {
      // 切换聊天框显示
      toggleChatBox() {
        this.showChatBox = !this.showChatBox;
        console.log(this.showChatBox)
      },

      // 发送消息
      sendMessage() {
        if (this.userInput.trim() !== '') {
          // 用户发送的消息
          const userMessage = { type: 'user', text: this.userInput };
          this.messages.push(userMessage);
          // 发送请求到API
          this.getBotResponse(this.userInput);
          this.userInput = ''; // 清空输入框
        }
      },

      // 获取聊天机器人的回复
      async getBotResponse(userInput) {
        try {
          // 请求API
          const response = await axios.post(`https://localhost:7071/api/ChatRobot/chat?problem=${encodeURIComponent(userInput)}`);
          
          // 获取聊天机器人的回答
          const botMessage = { type: 'bot', text: response.data.result };
          this.messages.push(botMessage);

          // 滚动到最后一条消息
          this.$nextTick(() => {
            const messagesContainer = this.$el.querySelector('.messages');
            messagesContainer.scrollTop = messagesContainer.scrollHeight;
          });
        } catch (error) {
          console.error('Error fetching bot response:', error);
        }
      }
    }
  });
</script>
<style>
  /* 页面内容样式 */
  body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
  }

  /* 悬浮按钮样式 */
  .chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #4FD675;
    color: white;
    border: none;
    border-radius: 50%;
    padding: 15px;
    font-size: 24px;
    cursor: pointer;
    z-index: 1000; /* 确保按钮在最上层 */
  }

  /* 左侧对话框 */
  .chat-box {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 300px;
    height: 400px;
    background-color: #f1f1f1;
    border-top-right-radius: 10px;
    border-top-left-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 15px;
    flex-direction: column;
    z-index: 999; /* 确保聊天框在页面最上层 */
  }

  .chat-header {
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
  }

  .messages {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    padding: 10px;
    height: 70%;
    background-color: #fff;
  }

  .input-container {
    display: flex;
    align-items: center;
  }

  .input-container input {
    width: 100%;
    padding: 8px;
    margin-right: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
  }

  .input-container button {
    padding: 8px 12px;
    background-color: #4FD675;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }

  .message {
    margin-bottom: 10px;
  }

  .message .user {
    font-weight: bold;
  }

  .message .bot {
    color: #555;
    background-color: #c3f9d2;
  }
</style>
<!-- start of banner -->
<div class="banner text-center">   
  <div class="container" id="taglist">     
    <div class="row">       
      <div class="col-lg-9 mx-auto">         
        <h1 class="mb-5">欢迎来到中国非物质文化遗产论坛<br>想要了解什么内容</h1>         
        <ul class="list-inline widget-list-inline">           
          <li class="list-inline-item"><a href="#" @click.prevent="saveTag(1)">#文化艺术</a></li>           
          <li class="list-inline-item"><a href="#" @click.prevent="saveTag(2)">#生活习俗</a></li>           
          <li class="list-inline-item"><a href="#" @click.prevent="saveTag(3)">#哲学思想</a></li>           
          <li class="list-inline-item"><a href="#" @click.prevent="saveTag(4)">#精神价值</a></li>           
          <li class="list-inline-item"><a href="#" @click.prevent="saveTag(5)">#工艺技艺</a></li>           
          <li class="list-inline-item"><a href="#" @click.prevent="saveTag(6)">#文学经典</a></li>         
        </ul>       
      </div>     
    </div>   
  </div>    
</div>


  <script>
    var vm = new Vue({
        el: "#taglist",
        data: {
            userid: localStorage["userid"],
            selecttopictype: "",
            list: new Array()
        },// 添加mounted生命周期钩子
        mounted() {
          this.getpost();  // 页面加载完成后自动执行getpost
        },
        methods: {
            saveTag(tagId) {
                const tagTypes = {
                  1: "文化艺术",
                  2: "生活习俗",
                  3: "哲学思想",
                  4: "精神价值",
                  5: "工艺技艺",
                  6: "文学经典"
                };
                const topicType = tagTypes[tagId];
                if (topicType) {
                  localStorage.setItem("selectedTag", topicType);
                  window.location.href = 'tags.html';
                }
            },
            getpost: function () {
                var topicType = this.selecttopictype == "1" ? "文化艺术" : this.selecttopictype == "2" ? "生活习俗" : this.selecttopictype == "3" ? "哲学思想" : this.selecttopictype == "4" ? "精神价值" : this.selecttopictype == "5" ? "工艺技艺" :"文学经典"
                axios.get("https://localhost:7071/api/Post?id=-1&userId=-1"+ 
                    "&topicType=" + topicType +
                    "&postType=N%2FA"
                    ).then((res) => 
                    {
                        res.data.sort((a, b) => new Date(b.time) - new Date(a.time));
                        for (d in res.data) {
                          if(res.data[d].isVisable==true)
                            this.list.push(res.data[d]);
                        }
                        console.log(this.list);
                    })
            },
        }
    })
  </script>
  <svg class="banner-shape-1" width="39" height="40" viewBox="0 0 39 40" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M0.965848 20.6397L0.943848 38.3906L18.6947 38.4126L18.7167 20.6617L0.965848 20.6397Z" stroke="#040306"
      stroke-miterlimit="10" />
    <path class="path" d="M10.4966 11.1283L10.4746 28.8792L28.2255 28.9012L28.2475 11.1503L10.4966 11.1283Z" />
    <path d="M20.0078 1.62949L19.9858 19.3804L37.7367 19.4024L37.7587 1.65149L20.0078 1.62949Z" stroke="#040306"
      stroke-miterlimit="10" />
  </svg>
  
  <svg class="banner-shape-2" width="39" height="39" viewBox="0 0 39 39" fill="none" xmlns="http://www.w3.org/2000/svg">
    <g filter="url(#filter0_d)">
      <path class="path"
        d="M24.1587 21.5623C30.02 21.3764 34.6209 16.4742 34.435 10.6128C34.2491 4.75147 29.3468 0.1506 23.4855 0.336498C17.6241 0.522396 13.0233 5.42466 13.2092 11.286C13.3951 17.1474 18.2973 21.7482 24.1587 21.5623Z" />
      <path
        d="M5.64626 20.0297C11.1568 19.9267 15.7407 24.2062 16.0362 29.6855L24.631 29.4616L24.1476 10.8081L5.41797 11.296L5.64626 20.0297Z"
        stroke="#040306" stroke-miterlimit="10" />
    </g>
    <defs>
      <filter id="filter0_d" x="0.905273" y="0" width="37.8663" height="38.1979" filterUnits="userSpaceOnUse"
        color-interpolation-filters="sRGB">
        <feFlood flood-opacity="0" result="BackgroundImageFix" />
        <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" />
        <feOffset dy="4" />
        <feGaussianBlur stdDeviation="2" />
        <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
        <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow" />
        <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
      </filter>
    </defs>
  </svg>

  

  <svg class="banner-shape-3" width="39" height="40" viewBox="0 0 39 40" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M0.965848 20.6397L0.943848 38.3906L18.6947 38.4126L18.7167 20.6617L0.965848 20.6397Z" stroke="#040306"
      stroke-miterlimit="10" />
    <path class="path" d="M10.4966 11.1283L10.4746 28.8792L28.2255 28.9012L28.2475 11.1503L10.4966 11.1283Z" />
    <path d="M20.0078 1.62949L19.9858 19.3804L37.7367 19.4024L37.7587 1.65149L20.0078 1.62949Z" stroke="#040306"
      stroke-miterlimit="10" />
  </svg>

  
  <svg class="banner-border" height="240" viewBox="0 0 2202 240" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path
      d="M1 123.043C67.2858 167.865 259.022 257.325 549.762 188.784C764.181 125.427 967.75 112.601 1200.42 169.707C1347.76 205.869 1901.91 374.562 2201 1"
      stroke-width="2" />
  </svg>
</div>
<!-- end of banner -->

<section class="section pb-0">
  <div class="container">
    <div class="row">
      <div class="col-lg-4 mb-5" id="likepost">
        <h2 class="h5 section-title">好文推荐</h2>
        <article class="card" v-for="(item, index) in list" :key="index">
          <div class="card-body">
            <h3 class="h4 mb-3"><a class="post-title" @click="getRowId(item.id)">{{item.title}}</a></h3>
            <ul class="card-meta list-inline">
              <li class="list-inline-item">
                  <span>{{item.userId}}</span>
                </a>
              </li>
              <li class="list-inline-item">
                <i class="ti-calendar"></i>{{ item.time.replace('T', ' ') }}
              </li>
              <li class="list-inline-item">
                <ul class="card-meta-tag list-inline">
                  <li class="list-inline-item"><a @click="storetag(item.topicType)">{{item.topicType}}</a></li>
                </ul>
              </li>
            </ul>
            <p>{{item.text.slice(0, 40)}}</p>
            <a href="post.html" class="btn btn-outline-primary"@click="getRowId(item.id)">Read More</a>
          </div>
        </article>
      </div>


      <div class="col-lg-4 mb-5" id="commentlist">
        <h2 class="h5 section-title">正在热议</h2>
        
        <article class="card" v-for="(item, index) in list" :key="index">
          <div class="card-body">
            <h3 class="h4 mb-3"><a class="post-title" @click="getRowId(item.id)">{{item.title}}</a></h3>
            <ul class="card-meta list-inline">
              <li class="list-inline-item">
                  <span>{{item.userId}}</span>
                </a>
              </li>
              <li class="list-inline-item">
                <i class="ti-calendar"></i>{{ item.time.replace('T', ' ') }}
              </li>
              <li class="list-inline-item">
                <ul class="card-meta-tag list-inline">
                  <li class="list-inline-item"><a @click="storetag(item.topicType)">{{item.topicType}}</a></li>
                </ul>
              </li>
            </ul>
            <p>{{item.text.slice(0, 40)}}</p>
            <a href="post.html" class="btn btn-outline-primary"@click="getRowId(item.id)">Read More</a>
          </div>
        </article>
      </div>
      
      <div class="col-lg-4 mb-5" id="personlike">
        <h2 class="h5 section-title">猜您喜欢</h2>
        <article class="card" v-for="(item, index) in list" :key="index">
          <div class="card-body">
            <h3 class="h4 mb-3"><a class="post-title" @click="getRowId(item.id)">{{item.title}}</a></h3>
            <ul class="card-meta list-inline">
              <li class="list-inline-item">
                  <span>{{item.userId}}</span>
                </a>
              </li>
              <li class="list-inline-item">
                <i class="ti-calendar"></i>{{ item.time.replace('T', ' ') }}
              </li>
              <li class="list-inline-item">
                <ul class="card-meta-tag list-inline">
                  <li class="list-inline-item"><a @click="storetag(item.topicType)">{{item.topicType}}</a></li>
                </ul>
              </li>
            </ul>
            <p>{{item.text.slice(0, 40)}}</p>
            <a href="post.html" class="btn btn-outline-primary"@click="getRowId(item.id)">Read More</a>
          </div>
        </article>
      </div>
      <div class="col-12">
        <div class="border-bottom border-default"></div>
      </div>
    </div>
  </div>
</section>

  <section class="section-sm">
    <div class="container" id="posttimelist">
      <div class="row justify-content-center">
        <div class="col-lg-8 mb-3 mb-lg-0">
          <h2 class="h5 section-title">最近发布</h2>
          
          <!-- 文章列表 -->
          <article class="card mb-4" v-for="(item, index) in paginatedList" :key="index">
            <div class="card-body">
              <h3 class="mb-3" @click="getRowId(item.id)">{{item.title}}</h3>
              <ul class="card-meta list-inline">
                <li class="list-inline-item">
                  <a href="author-single.html" class="card-meta-author">
                    <span>{{item.userId}}</span>
                  </a>
                </li>
                <li class="list-inline-item">
                  <i class="ti-calendar">{{ item.time.replace('T', ' ') }}</i>
                </li>
                <li class="list-inline-item">
                  <ul class="card-meta-tag list-inline">
                    <li class="list-inline-item">
                      <a @click="storetag(item.topicType)">{{item.topicType}}</a>
                    </li>
                  </ul>
                </li>
              </ul>
              <p>{{item.text.slice(0, 100)}}</p>
              <a class="btn btn-outline-primary" @click="getRowId(item.id)">Read More</a>
            </div>
          </article>

          <!-- 分页导航 -->
          <nav aria-label="Page navigation" class="mt-4">
            <ul class="pagination justify-content-center">
              <li class="page-item" :class="{ disabled: currentPage === 1 }">
                <a class="page-link" href="#" @click.prevent="changePage(currentPage - 1)">
                  上
                </a>
              </li>
              <li class="page-item" v-for="page in totalPages" :key="page" 
                  :class="{ active: page === currentPage }">
                <a class="page-link" href="#" @click.prevent="changePage(page)">
                  {{ page }}
                </a>
              </li>
              <li class="page-item" :class="{ disabled: currentPage === totalPages }">
                <a class="page-link" href="#" @click.prevent="changePage(currentPage + 1)">
                  下
                </a>
              </li>
            </ul>
          </nav>
        </div>
      </div>
    </div>
  </section>

<script>
  var vm = new Vue({
      el: "#likepost",
      data: {
          userid: localStorage["userid"],
          list: new Array()
      },
      mounted() {
        this.getpost();  
      },
      methods: {
          getpost: function () {
              const user = localStorage["userid"];
              axios.get("https://localhost:7071/api/Post?id=-1&userId=-1&topicType=N%2FA&postType=N%2FA"
                  ).then((res) => 
                  {
                      res.data.sort((a, b) => b.likeNum - a.likeNum); // 按照likeNum降序排序
                      const topTwoPosts = res.data;
                      let count = 0; 
                      for (let d in topTwoPosts) {
                        // 只有当帖子的userId不等于指定的userid且count小于2时才执行
                        if(String(topTwoPosts[d].userId) !== String(user) && count < 2 && topTwoPosts[d].isVisable==true) {
                            this.list.push(topTwoPosts[d]);
                            count++; // 每添加一个帖子,计数器加1
                        }
                        // 如果已经添加了两个帖子,就跳出循环
                        if(count >= 2) {
                            break;
                        }
                      }
                  })
          },
          storetag:function(topicType){
            localStorage.setItem("selectedTag", topicType);
            location.href = "tags.html";
          },
          getRowId:function(id){
            localStorage["num"]=id;
            location.href = "post.html";
          }
      }
  })
</script>
<script>
  var vm = new Vue({
      el: "#commentlist",
      data: {
          userid: localStorage["userid"],
          list: new Array()
      },
      mounted() {
        this.getpost();  
      },
      methods: {
          getpost: function () {
              const user = localStorage["userid"];
              axios.get("https://localhost:7071/api/Post?id=-1&userId=-1&topicType=N%2FA&postType=N%2FA"
                  ).then((res) => 
                  {
                    res.data.sort((a, b) => b.commentNum - a.commentNum); // 按照commentNum降序排序
                    const topTwoPosts = res.data;
                    let count = 0;
                    for (let d in topTwoPosts) {
                        // 只有当帖子的userId不等于指定的userid且count小于2时才执行
                        if(String(topTwoPosts[d].userId) !== String(user) && count < 2 && topTwoPosts[d].isVisable==true) {
                            this.list.push(topTwoPosts[d]);
                            count++; // 每添加一个帖子,计数器加1
                        }
                        // 如果已经添加了两个帖子,就跳出循环
                        if(count >= 2) {
                            break;
                        }
                    }
                  })
          },
          storetag:function(topicType){
            localStorage.setItem("selectedTag", topicType);
            location.href = "tags.html";
          },
          getRowId:function(id){
            localStorage["num"]=id;
            location.href = "post.html";
          }
      }
  })
</script>
<script>
  var vm = new Vue({
      el: "#personlike",
      data: {
          userid: localStorage["userid"],
          list: new Array(),
          topicsByFrequency: new Array(),// 明确类型定义
          mostCommonTopic: "",//如果 topicsByFrequency 为空或不存在，点赞前2，有的话就是按照有的推荐 
      },
      mounted() {
        this.analyzeMostCommonTopic(this.userid);  
      },
      methods: {
        analyzeMostCommonTopic: function() {
          const user = localStorage["userid"];
            return axios.get(`https://localhost:7071/api/Post?id=-1&userId=${user}&topicType=N%2FA&postType=N%2FA`)
                .then((res) => {
                    // 统计主题出现次数
                    const topicCounts = {};
                    
                    // 计算每个主题的出现次数
                    res.data.forEach(post => {
                        if (post.topicType in topicCounts) {
                            topicCounts[post.topicType]++;
                        } else {
                            topicCounts[post.topicType] = 1;
                        }
                    });
                    
                    // 将统计结果转换为数组并排序
                    this.topicsByFrequency = Object.entries(topicCounts)
                        .map(([topic, count]) => ({
                            topic: topic,
                            count: count
                        }))
                        .sort((a, b) => b.count - a.count);
                    
                    // 设置最常见的主题
                    this.mostCommonTopic = this.topicsByFrequency.length > 0
                        ? this.topicsByFrequency[0].topic
                        : '';
                    console.log("Topics sorted by frequency:", this.topicsByFrequency);
                    // 分析完成后立即调用 getpost
                    this.getpost();
                })
                .catch(error => {
                    console.error("Error analyzing topics:", error);
                });
        },
        getpost: function() {
            const user = localStorage["userid"];
            // 如果 topicsByFrequency 为空或不存在，使用默认查询
            if (!this.topicsByFrequency || this.topicsByFrequency.length === 0) {
                axios.get("https://localhost:7071/api/Post?id=-1&userId=-1&topicType=N%2FA&postType=N%2FA")
                    .then((res) => {
                        res.data.sort((a, b) => b.likeNum - a.likeNum);
                        let count = 0;
                        for (let d in res.data) {
                          if(res.data[d].isVisable==true){
                            if (String(res.data[d].userId) !== String(user) && count < 2) {
                                this.list.push(res.data[d]);
                                count++;
                            }}
                            if (count >= 2) break;
                        }
                    })
                    .catch(error => {
                        console.error("Error fetching posts:", error);
                    });
            } else {
                // 使用 topicsByFrequency 进行查询
                let totalPostsAdded = 0;
                const processNextTopic = (topicIndex) => {
                    if (totalPostsAdded >= 2 || topicIndex >= this.topicsByFrequency.length) {
                        return;
                    }
                    const currentTopic = this.topicsByFrequency[topicIndex].topic;
                    axios.get(`https://localhost:7071/api/Post?id=-1&userId=-1&topicType=${encodeURIComponent(currentTopic)}&postType=N%2FA`)
                        .then((res) => {
                            res.data.sort((a, b) => b.likeNum - a.likeNum);
                            for (let d in res.data) {
                              if(res.data[d].isVisable==true){
                                if (totalPostsAdded >= 2) break;
                                if (String(res.data[d].userId) !== String(user)) {
                                    this.list.push(res.data[d]);
                                    totalPostsAdded++;
                                }
                              }
                            }
                            if (totalPostsAdded < 2) {
                                processNextTopic(topicIndex + 1);
                            }
                        })
                        .catch((error) => {
                            console.log("Error fetching posts for topic:", currentTopic, error);
                            processNextTopic(topicIndex + 1);
                        });
                };
                processNextTopic(0);
            }
        },
          storetag:function(topicType){
            localStorage.setItem("selectedTag", topicType);
            location.href = "tags.html";
          },
          getRowId:function(id){
            localStorage["num"]=id;
            location.href = "post.html";
          }
      }
  })
</script>
<script>
  var vm = new Vue({
      el: "#posttimelist",
      data: {
          userid: localStorage["userid"],
          list: new Array(),
          currentPage: 1,
          itemsPerPage: 6,
      },
      mounted() {
        this.getpost();  
      },
      computed: {
        // 计算总页数
        totalPages() {
          return Math.ceil(this.list.length / this.itemsPerPage)
        },
        // 当前页显示的文章列表
        paginatedList() {
          const start = (this.currentPage - 1) * this.itemsPerPage
          const end = start + this.itemsPerPage
          return this.list.slice(start, end)
        }
      },
      methods: {
          // 切换页码
          changePage(page) {
            if (page >= 1 && page <= this.totalPages) {
              this.currentPage = page
              const section = document.getElementById('posttimelist');
              if (section) {
                section.scrollIntoView({ behavior: 'smooth' });
              }
            }
          },
          getpost: function () {
            var postInfo = {
                  id: "",
                  time: "",
                  userId: "",
                  text: "",
                  title: "",
                  likeNum: "",
                  commentNum:"",
                  isVisible: "",
                  topicType: "",
                  postType: "",
                  weight: ""
              }; 
              axios.get("https://localhost:7071/api/Post?id=-1&userId=-1&topicType=N%2FA&postType=N%2FA"
                  ).then((res) => 
                  {
                      res.data.sort((a, b) => new Date(b.time) - new Date(a.time));
                      for (d in res.data) {
                        if(res.data[d].isVisable == true){
                          postInfo.id = res.data[d].id;
                          postInfo.time = res.data[d].time;
                          postInfo.userId = res.data[d].userId;
                          // postInfo.text = res.data[d].text;
                          postInfo.text = res.data[d].text;
                          postInfo.title = res.data[d].title;
                          postInfo.likeNum = res.data[d].likeNum;
                          postInfo.commentNum = res.data[d].commentNum;
                          postInfo.isVisible = res.data[d].isVisible;
                          postInfo.topicType = res.data[d].topicType;
                          postInfo.postType = res.data[d].postType;
                          postInfo.weight = res.data[d].weight;
                          localStorage["postInfo"+res.data[d].id] = JSON.stringify(postInfo);
                          this.list.push(res.data[d]);
                        }
                      }
                  })
          },
          storetag:function(topicType){
            localStorage.setItem("selectedTag", topicType);
            location.href = "tags.html";
          },
          getRowId:function(id){
            localStorage["num"]=id;
            location.href = "post.html";
          }
      }
  })
</script>

<footer class="footer">
  <svg class="footer-border" height="214" viewBox="0 0 2204 214" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M2203 213C2136.58 157.994 1942.77 -33.1996 1633.1 53.0486C1414.13 114.038 1200.92 188.208 967.765 118.127C820.12 73.7483 263.977 -143.754 0.999958 158.899"
      stroke-width="2" />
  </svg>
  <div class="container">
      <div class="row align-items-center">
      <div class="col-md-5 text-center text-md-left mb-4">
          <ul class="list-inline footer-list mb-0">
            <li class="list-inline-item"><a href="privacy-policy.html">Privacy Policy</a></li>
          </ul>
      </div>
      <div class="col-md-2 text-center mb-4">
          <a href="index.html"><img class="img-fluid" width="100px" src="images/图标.png" alt="Reader | Hugo Personal Blog Template"></a>
      </div>
      <div class="col-12">
          <div class="border-bottom border-default"></div>
      </div>
      </div>
  </div>
  </footer>


  <!-- JS Plugins -->
  <script src="plugins/jQuery/jquery.min.js"></script>
  <script src="plugins/bootstrap/bootstrap.js"></script>
  <script src="plugins/slick/slick.min.js"></script>
  <script src="plugins/instafeed/instafeed.min.js"></script>
  <!-- Main Script -->
  <script src="js/script.js"></script></body>
</html>